package de.baumann.browser.activitys

import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import de.baumann.browser.R
import de.baumann.browser.adapter.NoticeAdapter
import de.baumann.browser.api.net.vo.Notice
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.INoticeView
import de.baumann.browser.present.NoticePresenter
import de.baumann.browser.utils.ViewUtil
import kotlinx.android.synthetic.main.activity_notice.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 * @author:
 * @date:2018/12/11 11:22
 * @discription: 公告消息页面
 */
class NoticeActivity : BaseOdinActivity<INoticeView, NoticePresenter<INoticeView>>(), INoticeView {

    private var noticeAdapter: NoticeAdapter? = null

    override fun getTitleText(): String {
        return getString(R.string.announcement_message)
    }

    override fun getLayout(): Int {
        return R.layout.activity_notice
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        rvNotice.layoutManager = LinearLayoutManager(mContext)
        noticeAdapter = NoticeAdapter(R.layout.recycler_item_notice)
        noticeAdapter!!.emptyView = ViewUtil.emptyView(mContext)
        rvNotice.adapter = noticeAdapter
        noticeAdapter!!.setOnItemClickListener { adapter, _, position ->
            val notice = (adapter.getItem(position) as Notice?)!!
            if (notice.status == 0) {
                presenter.noticeRead(notice.noticeId)
            }
            val intent = Intent(mContext, NoticeDetailActivity::class.java)
            intent.putExtra("title", notice.noticeTitle)
            intent.putExtra("content", notice.noticeContent)
            intent.putExtra("time", notice.createTime)
            startActivity(intent)
        }
    }

    override fun initData() {
        presenter.getNotice()
    }

    override fun createPresenter(): NoticePresenter<INoticeView>? {
        return NoticePresenter()
    }

    override fun createView(): INoticeView? {
        return this
    }

    override fun setNotices(notices: List<Notice>) {
        noticeAdapter!!.setNewData(notices)
    }

}
